package de.hs_mannheim.srn.prototyp.model;
import java.util.ArrayList;
import java.util.List;


/**
 * List of users
 * @author Tobias Hegemann
 *
 */
public class UserList {
	private List<User> users;
	
	public UserList() {
		this.users = new ArrayList<User>();
	}
	
	/**
	 * Creates a new user and returns his own personal generated password.
	 * This password will never be saved, so he should notice it.
	 * Null will be returned if user already exists!
	 * @param name of the User to create
	 * @return generated personal password for the new user, null if user already exists
	 */
	public String createUser(String name) {
		for(User user : users) {
			if(user.getName().equalsIgnoreCase(name)) {
				return null;
			}
		}
		User user = new User(name);
		return user.generate();
	}
	
	
	/**
	 * Returns the user with the given name or null if user cannot be found
	 * @param name
	 * @return requestes user or null if user cannot be found
	 */
	public User getUser(String name) {
		for(User user : this.users) {
			if(user.getName().equalsIgnoreCase(name)) {
				return user;
			}
		}
		return null;
	}
}
